﻿<Window x:Class="XPathTool.XPathWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="XPath By Example" Height="600" Width="700" 
    Icon="/XPathTool;component/Images/XPath40TruncMOre.jpg"
    xmlns:my="clr-namespace:XPathTool"
    WindowStartupLocation="CenterScreen">
    
    <DockPanel>
        <StatusBar DockPanel.Dock="Bottom">
            <TextBlock Name="txtStatusInfo" Text="{Binding StatusInfo}" />
        </StatusBar>
        <Grid DockPanel.Dock="Bottom" MinHeight="140">
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="{Binding ElementName=topCol1, Path=Width}" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            
            <Label Grid.Row="0" Target="{Binding ElementName=grdSuggestions}" Content="X_Path:" />
            <ScrollViewer Grid.Column="1" Name="grdSuggestions" VerticalContentAlignment="Stretch">
                <ListView ItemsSource="{Binding QuerySuggestions, NotifyOnSourceUpdated=True,
                                        NotifyOnTargetUpdated=True,
                                        UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" MinHeight="50">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Suggested Query" DisplayMemberBinding="{Binding Query}" />
                            <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="160" />
                            <GridViewColumn Header="Try It">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="E_valuate" Tag="{Binding Path=Query}"
                                                Command="{Binding Path=DataContext.EvaluateCommand, 
                                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"
                                                CommandParameter="{Binding Query}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </ScrollViewer>
            
            
            <Label Grid.Row="1" Target="{Binding ElementName=txtUserQuery}" Content="_Enter your Query:" />
            <TextBox Name="txtUserQuery" Grid.Row="1" Grid.Column="1" Text="{Binding XPathQuery}" >
                <!--<TextBox.InputBindings>
                    <KeyBinding Key="Return" Command="{Binding EvaluateCommand}" />
                    <KeyBinding Key="Enter" Command="{Binding EvaluateCommand}" />
                </TextBox.InputBindings>-->
            </TextBox>

            <Button Grid.Row="1" Grid.Column="2" Content="_Evaluate" IsDefault="True"
                    Command="{Binding EvaluateCommand}" Height="24" />

            <Label Grid.Row="2" Target="{Binding ElementName=txtResults}" Content="_Result:" />
            <TextBlock Grid.Row="2" Grid.Column="1" Name="txtResults" Text="{Binding XPathResults}" HorizontalAlignment="Stretch" />
        </Grid>

        <Grid Name="topGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="23" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="30" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />

            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" Name="topCol1"  />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Border Style="{StaticResource header}" Grid.ColumnSpan="3" Grid.Row="1">
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                    <Image HorizontalAlignment="Right" Margin="3 1 45 1" Source="/XPathTool;component/Images/XPath40TruncMOre.jpg" VerticalAlignment="Top"  />
                    <TextBlock  Text="XPath Auto-Suggest and Evaluate" HorizontalAlignment="Center" />
                </StackPanel>
            </Border>

            <my:XPathMenu  Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Left" />


            <Label Grid.Row="2" Target="{Binding ElementName=txtXml}" Content="_Sample XML:" />
            <TextBox Grid.Column="1" Grid.ColumnSpan="1" Name="txtXml" TextWrapping="Wrap" AcceptsTab="True" 
                     AcceptsReturn="True"
                     Grid.Row="2" 
                     Text="{Binding FormattedXml,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                     Background="Honeydew" 
                     HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                     SelectionChanged="txtXml_SelectionChanged" />

            <Button Grid.Row="2" Grid.Column="2" Content="Su_ggest" Command="{Binding SuggestCommand}" 
                    Height="24" ToolTip="Highlight a tag or node" VerticalAlignment="Top" />


        </Grid>
        
    </DockPanel>
</Window>
